package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.model.TiTwo;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.XImageLoader;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by itboye on 2017/4/10.
 */

public class ImageAdapter extends BaseAdapter {
    ArrayList<String[]> arrayList;
    private Context context;
    ArrayList<String> list;

    int seletepostion=-1;
    public ImageAdapter(ArrayList<String[]> arrayList, Context context) {
        this.arrayList = arrayList;
        this.context = context;

    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    public void getPositon(int positon){
        this. seletepostion=positon;
    }
    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View rootView = LayoutInflater.from(context).inflate(R.layout.item_zuoti_tupian,
                parent, false);
        ImageView imageView = (ImageView) rootView.findViewById(R.id.include_image);
        TextView name = (TextView) rootView.findViewById(R.id.include_text);
        Log.d("imageViewimageView", arrayList.get(position) + "");
        //答案
        ArrayList<String[]> answer = arrayList;
        TiTwo two = new TiTwo();

        String[] s1 = answer.get(position);
        List<String> userList = Arrays.asList(s1);
        two.setImg(userList.get(2));
        two.setXuan(userList.get(0));
        name.setText(two.getXuan());
        if(seletepostion==position){
            name.setTextColor(Color.parseColor("#009ff0"));
        }else{
            name.setTextColor(Color.parseColor("#808080"));
        }
        Log.d("XImageLoader", two.getImg() + "");
        XImageLoader.load(
                Const.IMAGE_HEAD + two.getImg(),
                imageView);
        return rootView;
    }
}
